<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * CodeIgniter
 *
 * An open source application development framework for PHP 4.3.2 or newer
 *
 * @package		CodeIgniter
 * @author		Pradeep Kumar
 * @copyright	Copyright (c) 2009, hyderabad, Inc.
 * @license		http://tech-pundits.com/license.html
 * @link		http://tech-pundits.com
 * @since		Version 1.0
 * @filesource
 */

// ------------------------------------------------------------------------

/**
 * Ip_tracker Class
 *
 * @package		CodeIgniter
 * @subpackage	Libraries
 * @category	Ip Tracker
 * @author		Pradeep Kumar
 */
class CI_Ip_tracker {
	
		public $ip = '';
		public $ipaddress = '';
		public $hostname = '';
		public $provider = '';
		public $country = '';
		public $countrycode = '';
		public $countryflag = '';
		public $state = '';
		public $city = '';
		public $areacode = '';
		public $postalcode = '';
		public $dmacode = '';
		public $latitude = '';
		public $longitude = '';
		public $queries = '';
		public $height = '200';
		public $width = '200';
		public $url = "http://www.infosniper.net/xml.php?ip_address=";
		public $embed_code = '<iframe width="%width%" height="%height%" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.co.in/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=hyderabad&amp;sll=40.798343,-98.163149&amp;sspn=29.061758,56.513672&amp;ie=UTF8&amp;hq=&amp;hnear=Hyderabad,+Andhra+Pradesh&amp;ll=%lati%,%long%&amp;spn=0.327639,0.44632&amp;z=10&amp;iwloc=A&amp;output=embed"></iframe>';
	
	/**
	 * @return unknown
	 */
	public function getAreacode() {
		return $this->areacode;
	}
	
	/**
	 * @return unknown
	 */
	public function getCity() {
		return $this->city;
	}
	
	/**
	 * @return unknown
	 */
	public function getCountry() {
		return $this->country;
	}
	
	/**
	 * @return unknown
	 */
	public function getCountrycode() {
		return $this->countrycode;
	}
	
	/**
	 * @return unknown
	 */
	public function getCountryflag() {
		return $this->countryflag;
	}
	
	/**
	 * @return unknown
	 */
	public function getDmacode() {
		return $this->dmacode;
	}
	
	/**
	 * @return unknown
	 */
	public function getHostname() {
		return $this->hostname;
	}
	
	/**
	 * @return unknown
	 */
	public function getIp() {
		return $this->ip;
	}
	
	/**
	 * @return unknown
	 */
	public function getIpaddress() {
		return $this->ipaddress;
	}
	
	/**
	 * @return unknown
	 */
	public function getLatitude() {
		return $this->latitude;
	}
	
	/**
	 * @return unknown
	 */
	public function getLongitude() {
		return $this->longitude;
	}
	
	/**
	 * @return unknown
	 */
	public function getPostalcode() {
		return $this->postalcode;
	}
	
	/**
	 * @return unknown
	 */
	public function getProvider() {
		return $this->provider;
	}
	
	/**
	 * @return unknown
	 */
	public function getQueries() {
		return $this->queries;
	}
	
	/**
	 * @return unknown
	 */
	public function getState() {
		return $this->state;
	}
	/**
	 * @return unknown
	 */
	public function getUrl() {
		return $this->url;
	}
	
	/**
	 * @return unknown
	 */
	public function getEmbed_code() {
		return $this->embed_code;
	}
	
	/**
	 * @return unknown
	 */
	public function getHeight() {
		return $this->height;
	}
	
	/**
	 * @return unknown
	 */
	public function getWidth() {
		return $this->width;
	}
	
	/**
	 * @param unknown_type $embed_code
	 */
	public function setEmbed_code($embed_code) {
		$this->embed_code = $embed_code;
	}
	
	/**
	 * @param unknown_type $height
	 */
	public function setHeight($height) {
		$this->height = $height;
	}
	
	/**
	 * @param unknown_type $width
	 */
	public function setWidth($width) {
		$this->width = $width;
	}

	/**
	 * @param unknown_type $areacode
	 */
	public function setAreacode($areacode) {
		$this->areacode = $areacode;
	}
	
	/**
	 * @param unknown_type $city
	 */
	public function setCity($city) {
		$this->city = $city;
	}
	
	/**
	 * @param unknown_type $country
	 */
	public function setCountry($country) {
		$this->country = $country;
	}
	
	/**
	 * @param unknown_type $countrycode
	 */
	public function setCountrycode($countrycode) {
		$this->countrycode = $countrycode;
	}
	
	/**
	 * @param unknown_type $countryflag
	 */
	public function setCountryflag($countryflag) {
		$this->countryflag = $countryflag;
	}
	
	/**
	 * @param unknown_type $dmacode
	 */
	public function setDmacode($dmacode) {
		$this->dmacode = $dmacode;
	}
	
	/**
	 * @param unknown_type $hostname
	 */
	public function setHostname($hostname) {
		$this->hostname = $hostname;
	}
	
	/**
	 * @param unknown_type $ip
	 */
	public function setIp($ip) {
		$this->ip = $ip;
	}
	
	/**
	 * @param unknown_type $ipaddress
	 */
	public function setIpaddress($ipaddress) {
		$this->ipaddress = $ipaddress;
	}
	
	/**
	 * @param unknown_type $latitude
	 */
	public function setLatitude($latitude) {
		$this->latitude = $latitude;
	}
	
	/**
	 * @param unknown_type $longitude
	 */
	public function setLongitude($longitude) {
		$this->longitude = $longitude;
	}
	
	/**
	 * @param unknown_type $postalcode
	 */
	public function setPostalcode($postalcode) {
		$this->postalcode = $postalcode;
	}
	
	/**
	 * @param unknown_type $provider
	 */
	public function setProvider($provider) {
		$this->provider = $provider;
	}
	
	/**
	 * @param unknown_type $queries
	 */
	public function setQueries($queries) {
		$this->queries = $queries;
	}
	
	/**
	 * @param unknown_type $state
	 */
	public function setState($state) {
		$this->state = $state;
	}
	
	/**
	 * Constructor
	 *
	 * @access	public
	 * @param	array	initialization parameters
	 */
	function CI_Ip_tracker($params = array())
	{
		if (count($params) > 0)
		{
			$this->initialize($params);		
		}
		
		log_message('debug', "Flash_video Class Initialized");
	}
	
	// --------------------------------------------------------------------
	
	/**
	 * Initialize Preferences
	 *
	 * @access	public
	 * @param	array	initialization parameters
	 * @return	void
	 */
	function initialize($params = array())
	{
		if (count($params) > 0)
		{
			foreach ($params as $key => $val)
			{
				if (isset($this->$key))
				{
					$this->$key = $val;
				}
			}
		}
	}
	
	function runCode()
	{
		$this->loadUrl();
	}
	
	function loadUrl()
	{
		$data = new DOMDocument();
		$url = $this->getUrl();
		$ip = $this->getIp();
	    $data->load( $url.$ip );
		$matchs = $data->getElementsByTagName( "result" );
		  foreach( $matchs as $match )
		  {
			  $states = $match->getElementsByTagName( "state" );
			  $state = $states->item(0)->nodeValue;
			  $this->setState($state); 
			  $ipaddresses = $match->getElementsByTagName( "ipaddress" );
			  $ipaddress = $ipaddresses->item(0)->nodeValue;
			  $this->setIpaddress($ipaddress);
			  $hostnames = $match->getElementsByTagName( "hostname" );
			  $hostname = $hostnames->item(0)->nodeValue;
			  $this->setHostname($hostname);
			  $providers = $match->getElementsByTagName( "provider" );
			  $provider = $providers->item(0)->nodeValue;
			  $this->setProvider($provider);
			  $countries = $match->getElementsByTagName( "country" );
			  $country = $countries->item(0)->nodeValue;
			  $this->setCountry($country);
			  $countrycodes = $match->getElementsByTagName( "countrycode" );
			  $countrycode = $countrycodes->item(0)->nodeValue;
			  $this->setCountrycode($countrycode);
			  $countryflag = $match->getElementsByTagName( "countryflag" );
			  $countryflag = $countryflag->item(0)->nodeValue;
			  $this->setCountryflag($countryflag);
			  $city = $match->getElementsByTagName( "city" );
			  $city = $city->item(0)->nodeValue;
			  $this->setCity($city);
			  $areacodes = $match->getElementsByTagName( "areacode" );
			  $areacode = $areacodes->item(0)->nodeValue;
			  $this->setAreacode($areacode);
			  $postalcodes = $match->getElementsByTagName( "postalcode" );
			  $postalcode = $postalcodes->item(0)->nodeValue;
			  $this->setPostalcode($postalcode);
			  $dmacodes = $match->getElementsByTagName( "dmacode" );
			  $dmacode = $dmacodes->item(0)->nodeValue;
			  $this->setDmacode($dmacode);
			  $latitudes = $match->getElementsByTagName( "latitude" );
			  $latitude = $latitudes->item(0)->nodeValue;
			  $this->setLatitude($latitude);
			  $longitudes = $match->getElementsByTagName( "longitude" );
			  $longitude = $longitudes->item(0)->nodeValue;
			  $this->setLongitude($longitude);
			  $queries = $match->getElementsByTagName( "queries" );
			  $queries = $queries->item(0)->nodeValue;
			  $this->setQueries($queries);
		  }
	}
	
	public function getGoogleMap()
	{
		$emb_code = $this->getEmbed_code();
		$replace = array('%width%','%height%','%lati%','%long%');
		$with = array($this->getWidth(),$this->getHeight(),$this->getLatitude(),$this->getLongitude());
		$res = str_replace($replace,$with,$emb_code);
		return $res;
	}
}
